﻿Option Explicit On ' Make sure all items are explicitly declared
Option Strict On ' Be Very Strict about things here!
Namespace ZuneCardr
    ''' <summary>Artist</summary>
    ''' <author>Comentsys</author>
    ''' <version>1.0.0</version>
    ''' <created>1st February 2009</created>
    ''' <modified>1st February 2009</modified>
    ''' <remarks>Artist Data</remarks>
    Public Class Artist

        ' Private Constants

        Private Const VAL_ARTIST_LARGE As String = "artistImageLarge"
        Private Const VAL_ARTIST_SMALL As String = "artistImageSmall"

        ' Private Members

        Private strID As String
        Private strName As String
        Private strURL As String
        Private strPlays As String
        Private strArtistLarge As String
        Private imgArtistLarge As New BitmapImage
        Private strArtistSmall As String
        Private imgArtistSmall As New BitmapImage
        Private _Tracks As New List(Of Track) ' Tracks
        Private blnSelected As Boolean = True

        ' Private Methods

        ''' <summary>GetTracks</summary>
        ''' <param name="Elements">Track XML Elements</param>
        Private Sub GetTracks(ByRef Elements As IEnumerable(Of XElement))
            _Tracks.Clear()
            For Each Result In Elements
                _Tracks.Add(New Track(Result))
            Next
        End Sub

        ' Public Methods

        ''' <summary>Constructor</summary>
        ''' <param name="Element">Element to Parse</param>
        Public Sub New(ByRef Element As XElement)
            Dim ImageDict As New Dictionary(Of String, String)
            strID = Element.<id>.Value
            strName = Element.<label>.Value
            strURL = Element.<url>.Value
            strPlays = Element.<totalPlays>.Value
            ImageDict = Social.GetImages(Element.<image>.<url>)
            If ImageDict.ContainsKey(VAL_ARTIST_SMALL) Then
                strArtistSmall = ImageDict.Item(VAL_ARTIST_SMALL)
                imgArtistSmall = New BitmapImage(New Uri(strArtistSmall))
            Else
                ' Use Default
            End If
            If ImageDict.ContainsKey(VAL_ARTIST_LARGE) Then
                strArtistLarge = ImageDict.Item(VAL_ARTIST_LARGE)
                imgArtistLarge = New BitmapImage(New Uri(strArtistLarge))
            Else
                ' Use Default
            End If
            GetTracks(Element.<track>) ' Tracks
            ImageDict = Nothing
        End Sub

        ''' <summary>Constructor</summary>
        ''' <param name="Elements">Elements to Parse</param>
        Public Sub New(ByRef Elements As IEnumerable(Of XElement))
            Dim ImageDict As New Dictionary(Of String, String)
            For Each Result In Elements
                strID = Result.<id>.Value
                strName = Result.<label>.Value
                strURL = Result.<url>.Value
                strPlays = Result.<totalPlays>.Value
                ImageDict = Social.GetImages(Result.<image>.<url>)
                If ImageDict.ContainsKey(VAL_ARTIST_SMALL) Then
                    strArtistSmall = ImageDict.Item(VAL_ARTIST_SMALL)
                    imgArtistSmall = New BitmapImage(New Uri(strArtistSmall))
                Else
                    ' Use Default
                End If
                If ImageDict.ContainsKey(VAL_ARTIST_LARGE) Then
                    strArtistLarge = ImageDict.Item(VAL_ARTIST_LARGE)
                    imgArtistLarge = New BitmapImage(New Uri(strArtistLarge))
                Else
                    ' Use Default
                End If
                GetTracks(Result.<track>) ' Tracks
            Next
            ImageDict = Nothing
        End Sub

        ''' <summary>ID</summary>
        ''' <returns>Zune ID</returns>
        Public ReadOnly Property ID() As String
            Get
                Return strID
            End Get
        End Property

        ''' <summary>Name</summary>
        ''' <returns>Name Text</returns>
        Public ReadOnly Property Name() As String
            Get
                Return strName
            End Get
        End Property

        ''' <summary>URL</summary>
        ''' <returns>URL Text</returns>
        Public ReadOnly Property URL() As String
            Get
                Return strURL
            End Get
        End Property

        ''' <summary>Plays</summary>
        ''' <returns>Numeric Plays Value</returns>
        Public ReadOnly Property Plays() As String
            Get
                Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(strPlays, "[^\d,]"))
            End Get
        End Property

        ''' <summary>PlaysFull</summary>
        ''' <returns>Full Plays Value</returns>
        Public ReadOnly Property PlaysFull() As String
            Get
                Return strPlays
            End Get
        End Property

        ''' <summary>ImageLarge</summary>
        ''' <returns>Large Artist Image</returns>
        Public ReadOnly Property ImageLarge() As BitmapImage
            Get
                Return imgArtistLarge
            End Get
        End Property

        ''' <summary>ImageSmall</summary>
        ''' <returns>Small Artist Image</returns>
        Public ReadOnly Property ImageSmall() As BitmapImage
            Get
                Return imgArtistSmall
            End Get
        End Property

        ''' <summary>Tracks</summary>
        ''' <returns>List of Tracks</returns>
        Public ReadOnly Property Tracks() As List(Of Track)
            Get
                Return _Tracks
            End Get
        End Property

        ''' <summary>Selected</summary>
        ''' <returns>Selected Value</returns>
        ''' <remarks>Use on ZuneCard Value</remarks>
        Public Property Selected() As Boolean
            Get
                Return blnSelected
            End Get
            Set(ByVal Value As Boolean)
                blnSelected = Value
            End Set
        End Property

    End Class
End Namespace